#!/usr/bin/python

a = 0x1234
b = 0x3456                      # multiplier


a_bits = []
b_bits = []
a_tmp = a
b_tmp = b
for i in range(16):
    a_bits.append(a_tmp & 0x1)
    b_bits.append(b_tmp & 0x1)
    a_tmp >>= 1
    b_tmp >>= 1

# print a_bits, b_bits

# for signed number, extend one bit
a_bits.append(a_bits[-1])
b_bits.append(b_bits[-1])
# make the length of bits to a even number
b_bits.append(b_bits[-1])

tmp_bits = [0] + b_bits
booth_array = []
for i in range(0,16+2,2):
    booth_array.append(tmp_bits[i] + tmp_bits[i+1] - 2*tmp_bits[i+2])

print booth_array


pp = []
a_temp = a
for i in booth_array:
    # pp.append(a*i)
    pp.append(a_temp*i)
    a_temp <<= 2

print pp
for i in pp:
    print "%x," % i,
print ""

sum = 0
for i in pp:
    sum += i

print sum
print "the real result is %d (%x)" % (a*b, a*b)

